package dujiu.leetcode.slidingWindow.fixed_lengthSlidingWindow;

public class P209 {
    public int minSubArrayLen(int target, int[] nums) {

        int length = nums.length;
        int left = 0;
        int sum = 0; // 子数组元素和
        int ans = 0; //符合条件的子数组的长度
        for (int right = 0; right < length; right++) { // 枚举子数组的右端点
            sum += nums[right];
            while (sum - nums[left] >= target){
                sum -= nums[left];
                left++;
            }
            if (sum >= target){
                ans = right-left+1;
            }
        }
        return ans <= length ? ans : 0;
    }
}
